package co.edu.usbcali.ai.ga;

import java.io.Serializable;


public class Gene<T extends Serializable> implements Serializable{
	
	private GeneType<T> geneType;
	private T value;
	
	/* **********************************************
	 * CONSTRUCTORS
	 * **********************************************/

	public Gene(GeneType<T> genType){
		geneType=genType;
	}

	public Gene(){
	}

	/* **********************************************
	 * 
	 * **********************************************/

	public Gene<T> cloneMutating(){
		Gene<T> gene=new Gene<T>(geneType);
		T obj;
		do{
			obj=geneType.getRandom();
			//spontaneusGeneration(getGeneType());
		}while (getValue().equals(obj));
		gene.setValue(obj);
		return gene;
	}
	
	
	@SuppressWarnings("unchecked")
	public boolean equals(Object p_gene){
		if (p_gene==null){
			return false;
		}else{
			Gene<T> other=(Gene<T>)p_gene;
			return getGeneType().equals(other.getGeneType())&&
				getValue().equals(other.getValue());
		}
	}
	
	
	public String toString(){
		return value.toString();
	}

	/* **********************************************
	 * GETTERS AND SETTERS
	 * **********************************************/

	public GeneType<T> getGeneType() {
		return geneType;
	}
	public void setGeneType(GeneType<T> geneType) {
		this.geneType = geneType;
	}

	public T getValue() {
		return value;
	}
	
	public void setValue(T value) {
		this.value = value;
	}


}
